<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/blueimp-md5/2.10.0/js/md5.min.js"></script> -->
<?php $GLOBALS['script'][] = function() {?><script>
vue.data.title = '账号注册/登录';
vue.data.disabled = 0;
vue.data.email_focus = false;
vue.data.flag = 'check';
vue.data.form.email = localStorage.email;
vue.data.form.vcode = '';
vue.data.form.password = '';
vue.data.form.password2 = '';
vue.watch.flag = function (_flag) {
    if (_flag === 'check') {
        vue.data.title = '账号注册/登录';
    }
    if (_flag === 'reg') {
        vue.data.title = '请完成注册信息';
    }
    if (_flag === 'login') {
        vue.data.title = '';
    }
    if (_flag === 'resetpwd') {
        vue.data.title = '请设置新密码';
    }
};
vue.methods.submit = function () {
    const urlParams = window.getParams();
    const that = this;
    const form = window.clone(that.form);
    if (urlParams.wxcode) {
        form.wxcode = urlParams.wxcode;
    }
    localStorage.email = form.email;
    form.password = md5(form.password);
    form.password2 = md5(form.password2);
    that.disabled++;
    var urlPath = '/public/email/check';
    if (that.flag === 'login') {
        urlPath = '/public/email/login';
    }
    if (that.flag === 'reg') {
        urlPath = '/public/email/verify/reg';
    }
    if (that.flag === 'resetpwd') {
        urlPath = '/public/email/verify/resetpwd';
    }
    that.ApiPost(urlPath, form).then(function (res) {
        // if (res.data.hasOwnProperty('flag')) that.flag = res.data['flag'];
        if (res.data.flag === 'unregistered') {
            if (confirm('您输入的邮箱尚未注册，请点击[确定]进行注册')) {
                that.disabled++;
                that.ApiPost('/public/email/sendvcode', form).then(function (res) {
                    that.flag = 'reg';
                }, function (res) {
                }).then(function (res) {
                    that.disabled--;
                });
            }
            $("#email").focus();
        }
        if (res.data.flag === 'registered') {
            that.flag = 'login';
        }
        if (res.data.flag === 'logined') {
            localStorage.setItem("push-menu", "expanded");
            location.href = '/panel/index.html';
        }
    }, function (res) {
        if (res.data.flag === 'check') {
            that.flag = 'check';
        }
        // console.log('reject:', res);
        // if (res.data.hasOwnProperty('flag')) that.flag = res.data['flag'];
    }).then(function (res) {
        that.disabled--;
        that.email_focus = true;
    }).catch(function (reason) {
        that.disabled--;
        console.log('catch:', reason);
    })
};
vue.methods.resetpwd = function () {
    const that = this;
    const form = window.clone(that.form);
    if (confirm('系统将向您的邮箱发送验证码，请点击[确定]继续')) {
        that.disabled++;
        that.ApiPost('/public/email/sendvcode', form).then(function (res) {
            that.flag = 'resetpwd';
        }, function (res) {
        }).then(function (res) {
            that.disabled--;
        });
    }
};
vue.methods.back = function () {
    const that = this;
    that.flag = 'check';
    // that.form.email = '';
    that.form.vcode = '';
    that.form.password = '';
    that.form.password2 = '';
};
</script><?php }?>

<table height="100%" width="100%"><tr><td>
<div class="login-box">
  <div class="login-logo">
    <a href=""><b><?=$GLOBALS['config']['title_full']?></b></a>
  </div>
  <!-- /.login-logo -->
  <div class="login-box-body">
<!--
    <p class="login-box-msg">简单&nbsp;&nbsp;&nbsp;高效&nbsp;&nbsp;&nbsp;安全&nbsp;&nbsp;&nbsp;可靠</p>
-->
    <p class="login-box-msg">{{title}}</p>

    <form action="" method="post" v-on:submit="submit">
      <div class="form-group has-feedback">
        <input
        id="email"
        type="email"
        class="form-control"
        placeholder="请输入Email"
        v-model="form.email"
        :disabled="disabled>0"
        required="required"
        autocomplete="off"
        v-focus="email_focus"
        />
        <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
      </div>
      <div class="form-group has-feedback" v-if="flag==='reg'||flag==='resetpwd'">
        <input
        type="text"
        class="form-control"
        placeholder="请输入6位邮箱验证码"
        v-model="form.vcode"
        :disabled="disabled>0"
        required="required"
        autocomplete="off"
        />
        <span class="glyphicon glyphicon-lock form-control-feedback"></span>
      </div>
      <div class="form-group has-feedback" v-if="flag==='reg'||flag==='login'||flag==='resetpwd'">
        <input
        type="text"
        class="form-control"
        placeholder="请输入登录密码"
        v-model="form.password"
        :disabled="disabled>0"
        required="required"
        onfocus="this.type='password'"
        autocomplete="off"
        />
        <span class="glyphicon glyphicon-lock form-control-feedback"></span>
      </div>
      <div class="form-group has-feedback" v-if="flag==='reg'||flag==='resetpwd'">
        <input
        type="text"
        class="form-control"
        placeholder="重复确认一次登录密码"
        v-model="form.password2"
        :disabled="disabled>0"
        required="required"
        onfocus="this.type='password'"
        autocomplete="off"
        />
        <span class="glyphicon glyphicon-lock form-control-feedback"></span>
      </div>
      <div class="row">
        <div class="col-xs-8" style="display: none;">
          <div class="checkbox icheck">
            <label>
              <input type="checkbox" :disabled="disabled>0"> 记住账号
            </label>
          </div>
        </div>
        <!-- /.col -->
        <div class="col-xs-4">
          <button type="button" class="btn btn-default btn-block btn-flat" :disabled="disabled>0" v-on:click="resetpwd" v-if="flag==='login'">
            重设密码
          </button>
        </div>
        <div class="col-xs-4">
          <button type="submit" class="btn btn-primary btn-block btn-flat" :disabled="disabled>0">
            <span v-if="flag==='login'">登录</span><span v-else>下一步</span>
          </button>
        </div>
        <div class="col-xs-4">
          <button type="button" class="btn btn-default btn-block btn-flat" :disabled="disabled>0" v-on:click="back" v-if="flag!=='check'">
            返回
          </button>
        </div>
        <!--
        <div class="col-xs-4" style="float: right;" v-if="flag==='login'">
          <button type="button" class="btn btn-default btn-block btn-flat" :disabled="disabled>0" v-on:click="resetpwd">重设密码</button>
        </div>
        <div class="col-xs-4" style="float: right;" v-if="flag!==''">
          <button type="button" class="btn btn-default btn-block btn-flat" :disabled="disabled>0" v-on:click="back">返回</button>
        </div>-->
        <!-- /.col -->
      </div>
    </form>
<!--
    <div class="social-auth-links text-center">
      <p>- OR -</p>
      <a href="#" class="btn btn-block btn-social btn-facebook btn-flat"><i class="fa fa-facebook"></i> Sign in using
        Facebook</a>
      <a href="#" class="btn btn-block btn-social btn-google btn-flat"><i class="fa fa-google-plus"></i> Sign in using
        Google+</a>
    </div>
    -->
    <!-- /.social-auth-links -->
<!--
    <a href="javascript:void(0)" onclick="button1.click()">忘记登录密码</a><br>
    <a href="javascript:void(0)" onclick="button1.click()">注册新账号</a>
-->
<?php
if (!empty($GLOBALS['config']['loginad'])) {
?>
<center style="padding-top: 10px;"><?=$GLOBALS['config']['loginad']?></center>
<?php
}
?>
  </div>
  <!-- /.login-box-body -->
</div>
<!-- /.login-box -->
</td></tr>
</table>

<?php $GLOBALS['script'][] = function() {?><script>
  $(function () {
    $('input').iCheck({
      checkboxClass: 'icheckbox_square-blue',
      radioClass: 'iradio_square-blue',
      increaseArea: '20%' /* optional */
    });
    //*
    $('form').submit(function() {
      //alert('asdf');
      return false;
    });//*/
  });
</script><?php }?>
